/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import entreprise.UserPatient;
import java.util.ArrayList;
import mapping.DBUserPatient;

/**
 *
 * @author duonghau
 */
public class UserPatientAdminBean {
    String userName;
    String patientID;
    String userPass;
    String userEmail;
    DBUserPatient dBUserPatient;
    String message="";
    String messageStyle="";    
    
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPatientID() {
        return patientID;
    }

    public void setPatientID(String patientID) {
        this.patientID = patientID;
    }

    public String getUserPass() {
        return userPass;
    }

    public void setUserPass(String userPass) {
        this.userPass = userPass;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getMessage() {
        return message;
    }

    public String getMessageStyle() {
        return messageStyle;
    }
    
    public ArrayList<UserPatient> getUserPatients(){
        dBUserPatient=new DBUserPatient();
        return dBUserPatient.getUsers("");
    }    
    
    public String deleteUser(String userName){
        dBUserPatient=new DBUserPatient();
        if(dBUserPatient.deleteUser(userName)){
            message="Delete success";
            messageStyle="success";
        }else{
            message="Delete error";
            messageStyle="error";            
        }
        return "users";
    }
    public String addUser(){
        dBUserPatient=new DBUserPatient();
        UserPatient userPatient=new UserPatient(patientID, userName, userPass);
        if(dBUserPatient.createUser(userPatient)){
            message="Add user success.";
            MailInform mailInform=new MailInform();
            String mailContent="Your user name is:<b>"+userName+"</b>, your password is: <b>"+userPass+"</b><br/>"
                    +"You are receiving this email because "+userEmail+" is registered on E-clinic";
            if(mailInform.sendMail("duonghau.emarketing@gmail.com", userEmail, "Create account success", mailContent)){
                message+="A email has been sent to user";
            }else{
                message+="Failed to send email to user";
            }            
            messageStyle="success";            
        }else{
            message="Add error";
            messageStyle="error";                
        }
        return "users";
    }
}
